﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class NoAnswerMessageInChannelsController : ControllerBase
    {

        private readonly INoAnswerMessageInChannelAppService _app;
        public NoAnswerMessageInChannelsController(INoAnswerMessageInChannelAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("noAnswerMessageInChannels/{id:Guid}")]
        public ActionResult<NoAnswerMessageInChannelDto> Get([FromRoute] Guid id)
        {
            NoAnswerMessageInChannelDto noAnswerMessageInChannel = _app.Get(id);
            return Ok(noAnswerMessageInChannel);
        }

        [HttpGet]
        [Route("bots/{botId:Guid}/noAnswerMessageInChannels")]
        public ActionResult<IEnumerable<NoAnswerMessageInChannelDto>> GetList([FromRoute] Guid botId)
        {
            IEnumerable<NoAnswerMessageInChannelDto> list = _app.GetByBotId(botId);
            return Ok(list);
        }

        [HttpPut]
        [Route("noAnswerMessageInChannels/{id:Guid}")]
        public ActionResult<NoAnswerMessageInChannelDto> Put([FromRoute] Guid id, [FromBody] NoAnswerMessageInChannelUpdateDto dto)
        {
            NoAnswerMessageInChannelDto noAnswerMessageInChannel = _app.Update(id, dto);
            return Ok(noAnswerMessageInChannel);
        }

        [HttpPost]
        [Route("bots/{botId:Guid}/noAnswerMessageInChannels")]
        public ActionResult<NoAnswerMessageInChannelDto> Post([FromRoute] Guid botId, [FromBody] NoAnswerMessageInChannelCreateDto dto)
        {
            NoAnswerMessageInChannelDto noAnswerMessageInChannel = _app.Add(botId, dto);
            return CreatedAtAction(nameof(Get), new { id = noAnswerMessageInChannel.Id }, noAnswerMessageInChannel);
        }

        [HttpDelete]
        [Route("noAnswerMessageInChannels/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
